package com.pega.tulokhorecord.activity.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pega.tulokhorecord.R;
import com.pega.tulokhorecord.data.TurnInfo;

public class TurnAdapter extends BaseAdapter {
	/* Variable Declaration */
	private Context context;

	private List<TurnInfo> list;

	private TurnInfo entry;
	private LayoutInflater inflater;

	public TurnAdapter(Context context, List<TurnInfo> list) {
		this.context = context;
		this.list = list;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public class ViewHolder {
		public TextView turn_no, point1, point2, point3, point4;

	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;

		entry = list.get(position);

		if (convertView == null) {

			convertView = inflater.inflate(R.layout.turn_item, null);

			holder = new ViewHolder();

			holder.turn_no = (TextView) convertView
					.findViewById(R.id.tv_turn_no);
			holder.point1 = (TextView) convertView
					.findViewById(R.id.tv_turn_point1);
			holder.point2 = (TextView) convertView
					.findViewById(R.id.tv_turn_point2);
			holder.point3 = (TextView) convertView
					.findViewById(R.id.tv_turn_point3);
			holder.point4 = (TextView) convertView
					.findViewById(R.id.tv_turn_point4);

			convertView.setTag(holder);
			// Set the display text
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		/*
		 * holder.couponName.setText(entry.getCouponName());
		 * holder.expirationDate.setText(context
		 * .getString(R.string.Coupon_Expiration_Date) + "\n" +
		 * entry.getExpirationDate());
		 * holder.usageDescription.setText(entry.getUsageDescription());
		 * holder.couponCode.setText(entry.getCouponCode());
		 * 
		 * holder.couponImage.setTag(Data.URL_BASE_2 + entry.getCouponImage());
		 * imageLoader.DisplayImage(Data.URL_BASE_2 + entry.getCouponImage(),
		 * (Activity) context, holder.couponImage); Log.v(Data.LOG3, "image" +
		 * entry.getCouponImage());
		 * 
		 * final Button savedMyCoupons = (Button) convertView
		 * .findViewById(R.id.CouponListAddtoMyCouponButton); if
		 * (entry.getSavedMyCoupons().equalsIgnoreCase("N")) { savedMyCoupons
		 * .setText(context.getString(R.string.Add_to_myCoupons));
		 * savedMyCoupons.setBackgroundResource(R.drawable.done_btn);
		 * savedMyCoupons.setTag(entry.getCouponId().toString());
		 * savedMyCoupons.setOnClickListener(new View.OnClickListener() {
		 * 
		 * public void onClick(View v) { // TODO Auto-generated method stub
		 * createProgressDialog();
		 * 
		 * new Loader().execute(savedMyCoupons.getTag().toString()); } });
		 * 
		 * } else if (entry.getSavedMyCoupons().equalsIgnoreCase("Y")) {
		 * savedMyCoupons.setText(context
		 * .getString(R.string.Already_Added_to_my_coupons));
		 * savedMyCoupons.setBackgroundColor(Color.WHITE);
		 * savedMyCoupons.setTextColor(Color.BLACK);
		 * 
		 * }
		 */
		// display the view corresponding to data at specified position
		convertView.setBackgroundResource(R.drawable.demo_card_selector_color1);
		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

			}
		});
		return convertView;

	}
}